/*******************************************************************************
 *  Copyright (c) 2017 Oliver Meili
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Eclipse Distribution License v1.0 which accompany this distribution.
 *   
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  The Eclipse Distribution License is available at
 *  http://www.eclipse.org/org/documents/edl-v10.php.
 *   
 *  Contributors:
 *  Oliver Meili <omi@ieee.org>
 *******************************************************************************/
package org.eclipse.vorto.codegen.ble.alpwise.templates

import java.io.File
import org.eclipse.vorto.codegen.api.InvocationContext
import org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel
import org.eclipse.vorto.codegen.ble.model.BleInvocationContext
import org.eclipse.vorto.codegen.ble.templates.BleGattTemplate

class AlpwiseFbHeaderTemplate extends BleGattTemplate<FunctionblockModel> {
	
	override getFileName(FunctionblockModel fb) {
		return fb.name + ".h";
	}
	
	override getPath(FunctionblockModel fb) {
		return rootPath + File.separator + fb.name;
	}
	
	override getContent(FunctionblockModel fb, InvocationContext context) {
'''
/* «fb.name» generated by Vorto */

#ifndef __«fb.name.toUpperCase»_H__
#define __«fb.name.toUpperCase»_H__

#include <stdint.h>
#include <AttBase.h>

#include "BleUtils.h"

#include "services/«findService((context as BleInvocationContext).getDevice(), fb).name»Service.h"

#define ENABLE_«fb.name.toUpperCase»_NOTIFICATIONS 1
#define NUM_«fb.name.toUpperCase»_SERVICES         1

// Configuration per service instance
typedef struct _«fb.name»_t {

	«findService((context as BleInvocationContext).getDevice(), fb).name»Service_t *service;

	// Configuration and status per characteristic
	«FOR status : fb.functionblock.status.properties»
		«IF context.getMappedElement(status, "source").hasAttribute("uuid")»
			uint8_t *«status.name.toFirstUpper»Value;
		«ENDIF»
	«ENDFOR»
	
} «fb.name»_t;

const «fb.name»_t «fb.name»_Instances[NUM_«fb.name.toUpperCase»_SERVICES];

void «fb.name»_Init(void);

«FOR status : fb.functionblock.status.properties»
	«IF context.getMappedElement(status, "source").hasAttribute("uuid")»
		void «fb.name»_Set«status.name.toFirstUpper»Value(«fb.name»_t *«fb.name.toLowerCase», «context.getMappedElement(status, "source").getAttributeValue("datatype", "uint16")»_t value);
	«ENDIF»
«ENDFOR»

#endif /* __«fb.name.toUpperCase»_H__ */
'''
	}
	
}
